<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            height: 50px;
            width: 250px;
            margin: 10px;
        }
    </style>
</head>

<body>
    <div id="one">
        <span>商品单价：</span>
        <input type="text"  value="12.9" id="money">
    </div>

    <div id="two">
        <span>商品数量：</span>
        <br>
        <button id="add">+</button>
        <input type="text" name="amount" value="1" id="num">
        <button id="minus">-</button>
    </div>

    <div id="three">
        <span>商品总价:</span>
        <br>
        <input type="text" name="totalprice" value="0.0" id="totalmoney">
    </div>

    <script>
        var adds = document.getElementById('add');
        var minus = document.getElementById('minus');

        var money = document.getElementById('money').value;
        var i = document.getElementById('num').value;

        adds.onclick = function(){
                i++;
                document.getElementById('num').value = i;
                document.getElementById('totalmoney').value = i*money;
        }

        minus.onclick = function(){
            if(i>0){
                i--;
                document.getElementById('num').value = i;
                document.getElementById('totalmoney').value = i*money;
            }
            else {
                i=0;
                document.getElementById('num').value = i;
                document.getElementById('totalmoney').value = 0;
            }
        }



 
    </script>
</body>

</html>